package y23.Sep;

public class Test7 {
    public static void main(String[] args) {
        System.out.println(isHappy(19));
        System.out.println(isHappy(2));
    }

    public static boolean isHappy(int n) {
        int slow = n;
        int fast = bitSum(n);
        while(slow != fast){
            slow = bitSum(slow);
            fast = bitSum(bitSum(fast));
        }
        return slow == 1;
    }
    public static int bitSum(int n){
        int sum = 0;
        while(n > 0){
            sum += Math.pow(n % 10,2);
            n/=10;
        }
        return sum;
    }
}